// 防抖
function debondse(func,delay) {
    var timer;
    return function() {
        let args = arguments;
        if(timer) {
            clearTimeout(timer);
            timer = null;
        }
        timer = setTimeout(() => {
            func(...args);
        },delay);
    }
}

function test(i) {
    console.log(i)
}
// const testFunc =  debondse(test,500);

// testFunc(1)
// testFunc(2)
// testFunc(3)
// setTimeout(()=>{
//     testFunc(4)
// },600)

// 节流
function throttle(func,delay) {
    let pre = new Date();
    return function() {
        let args = arguments;
        let cur = new Date();
        if(cur - pre < delay) {
            return;
        }else {
            func(...args);
            pre = cur;
        }
    }
}

const testFunc = throttle(test,500)
testFunc(1)
setTimeout(()=>{
    testFunc(2)
},501)
setTimeout(()=>{
    testFunc(3)
},600)
setTimeout(()=>{
    testFunc(4)
},800)
setTimeout(()=>{
    testFunc(5)
},1002)

